<template>
  <div class="new-wrap">
    <!-- <div class="login-wrap">
      <el-container class="login-login is-vertical">
        <div class="main flex-1">
          <div class="login-form flex flex-column">
            <h1 class="title">{{ loginTitle }}</h1>
            <div class="subtitle">常规登录</div>
            <div class="login-icon">
              <el-form
                :model="ruleForm"
                :rules="rules"
                ref="ruleForm"
                label-width="0px"
              >
                <el-form-item prop="username">
                  <el-input
                    v-model="ruleForm.username"
                    autocomplete="off"
                    placeholder="请输入用户名"
                  ></el-input>
                </el-form-item>
                <el-form-item prop="password">
                  <el-input
                    style="margin-top: 10px;"
                    type="password"
                    placeholder="请输入密码"
                    autocomplete="off"
                    v-model="ruleForm.password"
                    @keyup.enter.native="submitForm('ruleForm')"
                  ></el-input>
                </el-form-item>
                <div class="login-btn" @click="submitForm('ruleForm')">
                  登录
                </div>
              </el-form>
            </div>
          </div>
        </div>

      </el-container>
    </div>
    <div class="login-warp-bg"></div> -->
    <div class="new-content">
      <div class="new-box">
        <div class="new-left"></div>
        <div class="new-right">
          <div class="new-from">
            <el-form
              :model="ruleForm"
              :rules="rules"
              ref="ruleForm"
              label-width="0px"
            >
              <el-form-item prop="username" class="new-user">
                <img src="../../assets/images/logo-user.png" alt="" />
                <el-input
                  v-model="ruleForm.username"
                  autocomplete="off"
                  placeholder="请输入用户名"
                ></el-input>
              </el-form-item>
              <el-form-item prop="password" class="new-pwd">
                <img src="../../assets/images/logo-pwd.png" alt="" />
                <el-input
                  class="new-pwd"
                  style="margin-top: 10px;"
                  type="password"
                  placeholder="请输入密码"
                  autocomplete="off"
                  v-model="ruleForm.password"
                  @keyup.enter.native="submitForm('ruleForm')"
                ></el-input>
              </el-form-item>
            </el-form>
          </div>
          <div class="login-btn" @click="submitForm('ruleForm')"></div>
        </div>
      </div>
      <div class="new-abs">
        <div class="new-line1">
          <img src="../../assets/images/logo-yuan.png" alt="" />
        </div>
        <div class="new-line2">欢迎使用</div>
        <div class="new-line3">
          <img src="../../assets/images/logo-cs.png" alt="" />
        </div>
        <div class="new-line4">{{ loginTitle }}</div>
      </div>
    </div>
    <div class="footer new-foot">
      {{ footerCopyRightText }}
      <span class="admin-link" @click="$emit('change')">login</span>
    </div>
  </div>
</template>

<script>
import login_header from "@/assets/images/logo-header.png";
import { login } from "@/api/api.js";
import LoginService from "./service";

export default {
  data: function() {
    return {
      loginHeader: login_header,
      ruleForm: {
        username: "",
        password: ""
      },
      rules: {
        username: [
          { required: true, message: "请输入用户名", trigger: "blur" }
        ],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }]
      }
    };
  },
  computed: {
    loginTitle() {
      return window.pageData.login.loginTitle;
    },
    footerCopyRightText() {
      return window.pageData.login.footerCopyRightText;
    }
  },
  methods: {
    async submitForm(formName) {
      try {
        const valid = await this.$refs[formName].validate();
        await this._loginSync();
      } catch (error) {
        this.$message.error(error);
      }
    },
    async _loginSync() {
      const options = {
        loginAccount: this.ruleForm.username,
        loginPassword: this.ruleForm.password
      };
      const res = await login(options);
      if (!res.data.success) {
        throw res.data.message;
      }

      LoginService.saveUser(res.data.data);
      this.$router.push({ path: "home" });
    }
  }
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.new-wrap {
  display: flex;
  justify-content: center;
  align-items: Center;
  height: 100%;
  background: #f8f9fb;
}
.new-foot {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  text-align: center;
  font-weight: 400;
  color: rgba(100, 99, 99, 1);
  font-size: 12px;
  line-height: 36px;
}
.new-fix {
  position: fixed;
  right: 0;
  bottom: 0;
  width: 200px;
  height: 200px;
}
.new-box {
  width: 960px;
  margin: 0 auto;
  display: flex;
  margin-top: 320px;
  position: relative;
  .new-left {
    background: #1e212c;
    width: 480px;
    height: 200px;
  }
  .new-right {
    background: #fff;
    width: 480px;
    height: 200px;
    display: flex;
    position: relative;
    .new-from {
      padding-left: 50px;
      width: 350px;
      display: flex;
      align-items: center;
      .el-form {
        width: 90%;
      }
      .el-form-item {
        position: relative;
        img {
          position: absolute;
          top: 5px;
          left: 0;
          width: 20px;
          z-index: 2;
        }
        /deep/.el-input__inner {
          padding-left: 30px;
        }
      }
      .new-pwd {
        img {
          top: 21px;
        }
      }
    }
    .login-btn {
      cursor: pointer;
      width: 92px;
      height: 42px;
      background: url("../../assets/images/logo-btn.png") no-repeat center right;
      background-size: 92px 42px;
      position: absolute;
      bottom: 58px;
      right: 20px;
    }
  }
}
/deep/ .el-input__inner {
  border: none;
  height: 36px;
  line-height: 36px;
  border-bottom: 1px solid #c9cdd0;
}
.new-abs {
  position: absolute;
  width: auto;
  top: 278px;
  left: 170px;
  img {
    display: block;
    width: 100%;
  }
  .new-line1 {
    width: 70px;
    height: 70px;
    margin-bottom: 30px;
  }
  .new-line2 {
    color: #e0e0e0;
    font-size: 26px;
    font-weight: 400;
    margin-bottom: 10px;
  }
  .new-line3 {
    width: 76px;
    // height: 19px;
    margin-bottom: 10px;
  }
  .new-line4 {
    color: #e0e0e0;
    font-size: 20px;
    font-weight: 800;
  }
}
.new-content {
  position: relative;
  width: 1200px;
  height: 500px;
  background: url("../../assets/images/logo-bg.png") no-repeat center right;
  background-size: 1200px 440px;
}
.login-wrap {
  position: fixed;
  height: 100%;
  width: 100%;
  z-index: 2;
  background: url("../../assets/images/back-ground1.png") no-repeat center right;
  background-size: auto;
}
.login-warp-bg {
  position: fixed;
  height: 100%;
  width: 100%;
  z-index: 1;
  background-image: linear-gradient(to right, #095cfe 27%, #0ebcfb 98%);
}
.login-login {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  min-width: 800px;
}

.login-login .main {
  position: relative;
  top: 0;
  left: 0;
  width: 100%;
  height: calc(100% - 66px);
  min-height: 400px;
}
.login-icon {
  width: 353px;
  height: 50px;
  border-radius: 4px;
  margin-top: 119px;
}
.login-form {
  position: absolute;
  top: 50%;
  width: 353px;
  right: 387px;
  text-align: center;
  transform: translate(0, -53%);
  height: 62%;
}

.login-form .title {
  font-size: 40px;
  font-weight: 600;
  color: #ffffff;
  margin-bottom: 10px;
}

.login-form .subtitle {
  color: #ffffff;
  font-size: 22px;
  font-weight: 300;
}

.login-form .login-btn {
  background-color: #ffffff;
  color: #018aff;
  font-size: 20px;
  height: 50px;
  line-height: 50px;
  border-radius: 30px;
  margin-top: 145px;
  cursor: pointer;
}
.admin-link {
  color: transparent;
  display: inline-block;
  height: 50px;
  width: 100px;
  cursor: pointer;
  float: right;
}
</style>

<style>
.login-form .login-icon .el-input__inner {
  height: 50px !important;
  font-size: 16px;
  border-radius: 4px;
  opacity: 1;
}
input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0px 1000px rgba(255, 255, 255) inset;
}
</style>
